﻿using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Remoting;
using System.Threading;
using EasyHook;
using EasyHookSandbox.Ipc;

namespace EasyHookSandbox
{
    internal class Program
    {
        private static string _channelName = null;

        private static void Main(string[] args)
        {
            Process proc;

            while (true)
            {
                proc = Process.GetProcesses().AsEnumerable().FirstOrDefault(p => p.ProcessName.Contains("notepad"));
                if (proc != null) break;

                Thread.Sleep(1000);
            }

            var exeDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            Config.Register("Description", exeDirectory + "\\EasyHookSandbox.exe", exeDirectory + "\\EasyHookSandBox.Injector.dll");
            RemoteHooking.IpcCreateServer<HookChannel>(ref _channelName, WellKnownObjectMode.SingleCall);
            RemoteHooking.Inject(proc.Id, "EasyHookSandBox.Injector.dll", "EasyHookSandBox.Injector.dll", _channelName);

            Console.ReadLine();
        }
    }
}
